package com.sunrise.xdoc.entity.store;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;

import org.hibernate.annotations.Cascade;
import org.hibernate.validator.constraints.Length;
import org.hibernate.validator.constraints.NotBlank;

import com.sunrise.xdoc.entity.AbstractCodeEntity;
import com.sunrise.xdoc.entity.config.ChiNhanh;

@Entity
@Table(name = "store_kho")
@Inheritance(strategy = InheritanceType.JOINED)
public class Kho extends AbstractCodeEntity {
	private static final long serialVersionUID = 1L;
	private ChiNhanh chiNhanh;
	private String name;
	private String thongTin;
	private List<ChiTietKho> chiTietKhos = new ArrayList<>();

	@ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "chi_nhanh_id")
	@NotNull
	public ChiNhanh getChiNhanh() {
		return chiNhanh;
	}

	public void setChiNhanh(ChiNhanh chiNhanh) {
		this.chiNhanh = chiNhanh;
	}

	@Column(name = "name", unique = true)
	@Length(max = 250)
	@NotBlank
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@Column(name = "thongTin")
	@Length(max = 1024)
	public String getThongTin() {
		return thongTin;
	}

	public void setThongTin(String thongTin) {
		this.thongTin = thongTin;
	}

	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "kho")
	@Cascade(value = { org.hibernate.annotations.CascadeType.SAVE_UPDATE, org.hibernate.annotations.CascadeType.DELETE })
	public List<ChiTietKho> getChiTietKhos() {
		return chiTietKhos;
	}

	public void setChiTietKhos(List<ChiTietKho> chiTietKhos) {
		this.chiTietKhos = chiTietKhos;
	}
}
